package org.smarthings.http;

import org.smarthings.Callback;
import org.smarthings.Client;
import org.smarthings.Message;
import org.smarthings.Response;
import org.smarthings.Utils;

public class HttpClientImpl implements Client {
	private String baseUrl;

	public void start(String host, int port) {
		baseUrl = "http://" + host + ":" + port + "/";
	}

	public void stop() {
		// do nothing
	}

	public String getProtocol() {
		return HttpFactory.PROTOCOL;
	}

	public Message get(String path, String contentType) {
		String uri = Utils.normalizeUri(path);
		Message message = Utils.httpGET(baseUrl + uri, contentType);
		if (message != null) {
			message.setProtocol(HttpFactory.PROTOCOL);
		}
		return message;
	}

	public Response post(Message message) {
		return Utils.httpPOST(baseUrl + message.getUri(), message);
	}

	public void subscribe(String uri, String contentType, Callback callback) {
		// do nothing
	}
}